package com.cssw.fyzb.web.service;

import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;

import com.cssw.fyzb.core.dao.system.SysUserDao;
import com.cssw.fyzb.core.model.dodb.User;
import com.cssw.fyzb.web.vo.UserVo;
import com.ydn.dbframe.plugin.activerecord.Db;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Auther: zzf
 * @Date: 2020/12/2 15:22
 * @Description:AddAppealVo
 */
@Service
public class UserService {

    @Autowired
    private SysUserDao userDao;

    public AjaxPage<User> list(int page, int limit, Map param) {
        Page<User> list = userDao.list(page, limit, param);
        return AjaxPage.success(list.getList(), list.getTotalRow(), list.getTotalPage());
    }

    public AjaxData getDetails(String userId) {
        User details = userDao.getDetails(userId);
        UserVo userVo = new UserVo();
        userVo.setUserName(details.getUserName());
        userVo.setSex(details.getSex());
        userVo.setProvince(details.getProvince());
        userVo.setCity(details.getCity());
        userVo.setDistrict(details.getDistrict());
        userVo.setStatus(details.getStatus());
        userVo.setIdCard(details.getIdCard());
        userVo.setBirthday(details.getBirthday().toString());
        userVo.setImsi(details.getImsi());
        userVo.setFaceAuth(details.getFaceAuth());
        userVo.setUserLevel(details.getUserLevel().toString());
        userVo.setTeamLevel(details.getTeamLevel().toString());
        userVo.setCreateTime(details.getCreateTime().toString());
        userVo.setSupUserName(details.getStr("sup_user_name"));
        userVo.setSourceName(details.getStr("source_name"));
        userVo.setWechatNo(details.getStr("wechat_no"));
        userVo.setWechatCreatetTime(details.getStr("wechat_createt_time"));
        userVo.setWechatUpdateTime(details.getStr("wechat_update_time"));
        userVo.setAliNo(details.getStr("ali_no"));
        userVo.setAliCreatetTime(details.getStr("ali_createt_time"));
        userVo.setAliUpdateTime(details.getStr("ali_update_time"));
        userVo.setValidUser(details.getStr("valid_user"));
        userVo.setActiveNum(details.getStr("active_num"));
        userVo.setFans(details.getStr("fans"));
        userVo.setFriends(details.getStr("friends"));
        userVo.setProductions(details.getStr("productions"));
        userVo.setLikes(details.getStr("likes"));
        userVo.setOtherNum(details.getStr("other_num"));
        userVo.setVipLevelName(details.getStr("vip_level_name"));
        return AjaxData.success(userVo);
    }

    /**
     * 启用
     *
     * @param
     * @return
     */
    public AjaxData start(Long userId) {
        userDao.updateStatus(userId, User.STATUS_NORMAL);
        return AjaxData.success();
    }

    /**
     * 冻结
     *
     * @param
     * @return
     */
    public AjaxData stop(Long userId) {
        userDao.updateStatus(userId, User.STATUS_FROZEN);
        return AjaxData.success();
    }
}
